package com.zhou.cloud.controller;

import com.zhou.cloud.dao.entity.Person;
import com.zhou.cloud.service.IMongodbPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhouyongjun
 * @Description:
 * @date 2021/4/6 16:45
 */
@RestController
@RequestMapping("person")
public class PersonController {
    @Autowired
    IMongodbPersonService mongodbPersonService;
    @GetMapping("/get/{id}")
    public Person get(@PathVariable("id") Long id) {
        Person person = mongodbPersonService.find(id);
        System.out.println(person);
        return person;

    }
    @PostMapping("/add")
    public boolean add(Person person) {
        return mongodbPersonService.insert(person) != 0;
    }

    @DeleteMapping("del/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return false;
    }

    @GetMapping("/list")
    public List<Person> list() {
        List<Person> list = mongodbPersonService.findAll();
        System.out.println(list);
        return list;
    }
}
